//
// As of Sept 2010, the implementation of Format() in ATL's CStringT uses a
// fixed internal buffer of 1024 bytes; any output beyond that point will
// be silently truncated.  (AppendFormat() is affected by the same bug.)
// A bug has been filed with Microsoft; in the meantime, we provide the
// following safer implementations of Format/AppendFormat.  These functions
// currently support up to MAX_INT characters and will return an HRESULT
// error code on overflow or invalid parameters.

#ifndef LONGKEY_BASE_SAFE_FORMAT_H_
#define LONGKEY_BASE_SAFE_FORMAT_H_

#include <atlstr.h>
#include <strsafe.h>

void SafeCStringWFormatV(CStringW* dest_str,
	LPCWSTR format_str,
	va_list arg_list);

void SafeCStringAFormatV(CStringA* dest_str,
	LPCSTR format_str,
	va_list arg_list);

void SafeCStringWFormat(CStringW* dest_str, LPCWSTR format_str, ...);

void SafeCStringAFormat(CStringA* dest_str, LPCSTR format_str, ...);

void SafeCStringWAppendFormat(CStringW* dest_str, LPCWSTR format_str, ...);

void SafeCStringAAppendFormat(CStringA* dest_str, LPCSTR format_str, ...);


#ifdef UNICODE
#define SafeCStringFormatV       SafeCStringWFormatV
#define SafeCStringFormat        SafeCStringWFormat
#define SafeCStringAppendFormat  SafeCStringWAppendFormat
#else
#define SafeCStringFormatV       SafeCStringAFormatV
#define SafeCStringFormat        SafeCStringAFormat
#define SafeCStringAppendFormat  SafeCStringAAppendFormat
#endif  // UNICODE

#endif  // LONGKEY_BASE_SAFE_FORMAT_H_
